import { http } from '@/utils/http'
import { CartItem } from '@/types/cart'

// 加入购物车
export const addToCart = (data: { skuId: string; count: number }) => {
  return http({
    url: '/member/cart',
    method: 'POST',
    data
  })
}

// 查询购物车列表
export const getCartList = () => {
  return http<CartItem[]>({
    url: '/member/cart'
  })
}

// 删除购物车
export const delCart = (data: { ids: string[] }) => {
  return http({
    url: '/member/cart',
    method: 'DELETE',
    data
  })
}

// 更改商品数量和选中状态
export const updateCart = (
  id: string,
  data: { count?: number; selected?: boolean }
) => {
  return http({
    url: `/member/cart/${id}`,
    method: 'PUT',
    data
  })
}

/**
 * 全选&反选
 * ids不传，就是所有的商品
 */
export const selectAllOrNot = (data: { ids?: string[]; selected: boolean }) => {
  return http({
    url: '/member/cart/selected',
    method: 'PUT',
    data
  })
}
